package com.ycy.lock;

import org.apache.zookeeper.KeeperException;

public class Producer {

  static volatile int i = 0;

//  public static void main(String[] args) {

//    int thread = 100;
//
//    CountDownLatch countDownLatch = new CountDownLatch(thread);
//    Long l = System.currentTimeMillis();
//    for (int j = 0; j < thread; j++) {
//      new Thread(new Runnable() {
//        @Override
//        public void run() {
//
//          try {
//            Lock lock = new Lock();
//            count(lock);
//          } catch (IOException | KeeperException | InterruptedException e) {
//            e.printStackTrace();
//          }
//
//          countDownLatch.countDown();
//        }
//      }).start();
//    }
//
//    try {
//      countDownLatch.await();
//    } catch (InterruptedException e) {
//      e.printStackTrace();
//    }
//
//    //54034耗时
//    //99950 完成 ！！！
//    System.out.println((System.currentTimeMillis() - l) + "耗时");
//    System.out.println(i + " 完成 ！！！ ");

//  }

  public static void count(Lock lock) throws KeeperException, InterruptedException {

    for (int j = 0; j < 10; j++) {
      lock.tryLock();
      int b = i;
      Thread.sleep(10);
      b = b + 1;
      i = b;
//      System.out.println(Thread.currentThread().getName());
      lock.release();

    }


  }

  static int count = 0;

  // 1 2
  public static int fun(int i) {

    if (i <= 0) {
      return 0;
    }
    if (i == 1) {
      return 1;
    }
    if (i == 2) {
      return 2;
    }
    count++;
    return fun(i - 1) + fun(i - 2);
  }

  public static int fun1(int i, boolean aa) {
    int a = 1;
    int b = 2;
    if (i == a) return a;
    if (i == b) return b;
    int sum = 0;
    for (int j = 0; j < i - 2; j++) {
      sum = a + b;
      a = b;
      b = sum;
    }
    return sum;
  }

  public static void main(String[] args) {
    System.out.println(fun(8));
    System.out.println(count);

    Integer a = 222;
    Integer b = 222;
    System.out.println(a == b);
    System.out.println(fun1(4, false));

  }

}
